package com.magnificent.atlantis.client.robot.ui.configure.table.renderer;

import com.magnificent.commons.utils.collections.CollectionsUtils;

import javax.swing.*;
import javax.swing.table.TableCellRenderer;
import java.awt.*;

/**
 * User: Babanin
 * Date: Aug 29, 2009
 * Time: 2:17:16 AM
 */
public class ComboBoxCellRenderer extends JComboBox implements TableCellRenderer {

    public ComboBoxCellRenderer(Object[] strategies) {
        super(strategies);
    }

    public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) {
        if (isSelected) {
            setBackground(table.getSelectionBackground());
        } else {
            setForeground(table.getForeground());
            setBackground(table.getBackground());
        }

        setSelectedItem(value);

        return new JComboBox(CollectionsUtils.array(value));
    }
}
